<?php 

class otherModel extends appModel
{
	public function clear_db()
	{
		$count = $this->check_num();
		if($count == 0)
		{
			return true;
		}
		if($this->drop_table('random'))
		{
			return $this->created('random');
		}
		else
		{
			return false;
		}
	}
	
	public function drop_table($table)
	{
		$count=count($table);
	
		if(empty($count))
		{
			return Null;
		}

		$tab =  $this->table($table);
		
		$sql = "DROP TABLE IF EXISTS ".$tab.";";
		return $this->query($sql);
	}
	
	public function created($table)
	{
		$sql = "CREATE TABLE ".$this->table($table)."(
		random_id int NOT NULL AUTO_INCREMENT ,
		random_code varchar(255),
		PRIMARY KEY(random_id)
		)ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
		return $this->query($sql);
	}
	
	public function check_is_exist($arr)
	{
		$sql = "select count(*) from ".$this->table('random')." where random_code='".$arr."'";
		return $this->getOne($sql);
	}
	
	public function insert_random($arr)
	{
		$sql = "insert into ".$this->table('random')." (`random_code`) values ('".$arr."')";
		return $this->query($sql);
	}
	
	public function check_num()
	{
		$count = $this->getOne("select count(*) from ".$this->table('random'));
		return $count;
	}
	
	public function get_code()
	{
		$sql = "select * from ".$this->table('random');
		return $this->getAll($sql);
	}
}

?>